<include file="../header" />
<body class="J_scroll_fixed">
<script type="text/javascript">
    $(function() {
        $(document).off('change','#upload').on('change','#upload',function(){
//            $("input#upload").change(function(){
            //上传文件
            $(".top").hide();
            $.ajaxFileUpload({
                url:"{:U('activity/uploadExcel?className=FinishedProduct')}",//处理图片脚本
                secureuri :false,
                fileElementId :'upload',//file控件id
                dataType : 'json',
                success : function (data, status){
//                    alert(data.message);
                    alert("成功导入 " + data.count + " 条数据；重复数据 " + data.duplicated + " 条；无效数据 " + data.invalid + " 条。");
                    $(".top").show();
                    $("input#upload").val("");
                    if(data.count > 0){
                        var url = "/admin/FinishedProduct/index";
                        window.location.href = url;
                    }
                },
                error: function(data, status, e){
                    alert(e);
                    $(".top").show();
                    $("input#upload").val("");
                }
            })

        });
    })
</script>
<script language="javascript" src="/Template/js/ImgPreview.js"></script>
<style type="text/css">
    .btn-danger,.btn-info,.btn-success,.btn-warning{
        width: 60px;
        /*height: 18px;*/
        padding: 2px 0px 2px 0px;
        margin: 1px 0px 1px 0px;
    }
    .top {
        height: 25px;
        width: 120px;
        background-color: #1dccaa;
        line-height: 25px;
        cursor: pointer;
        display: inline-block;
        text-align: center;
        color: #fff;
        border-radius: 3px;
    }
</style>

<form class="well form-search" method="post" style="float:left;width:100%;" action="{:U('finishedProduct/index')}">
    <div class="search_type cc mb10">
        <div class="mb10">
        <span class="mr20">
            类型：
            <select name="fp#class_id-eq">
                     {:getCommonSelectOptionHtml($class_id, "Class", "class_id", "class_name", null, $user['enterprise_code'], 1)}
             </select>
            名称：<input type="text" name="name-like" value="{$name}" />
            产品编码：<input type="text" name="number-like" value="{$number}" />
            <!--功能：<input type="text" name="function-like" value="{$function}" />-->
            <!--适应症：<input type="text" name="indication-like" value="{$indication}" />-->
            <button class="btn btn-primary">搜索</button>
            <a class="btn" href="{:U('finishedProduct/index')}">重置</a>
        </span>
        </div>
    </div>
    <br/>
    <div class="controls">
        数据：
        <label for="upload" class="top">导入Excel文件</label>
        <input type="file" multiple id="upload" style="display: none;" name="fileToUpload" accept=".xls,.xlsx,.csv"/>
        <!--input id="fileToUpload" type="file" name="fileToUpload" style="width:170px;" accept=".xls,.xlsx,.csv">
        <button class="btn btn-success" id="upload1">上传</button-->
        &nbsp;&nbsp;
        <a style="color:#45a1de; font-size: medium" href="https://xwk-file.oss-cn-qingdao.aliyuncs.com/Home/成品导入模板.xlsx">下载Excel模板</a>
    </div>
</form>

<div class="wrap J_check_wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:U('finishedProduct/index')}">成品信息</a></li>
        <li><a href="{:U('finishedProduct/add')}">添加成品</a></li>
        <li><a href=""> </a></li><li><a href=""> </a></li>
        <li><a style="color: #ffa21c;font-weight: bold;text-decoration:underline;" href="{:U('finishedProduct/classlist')}">分类列表</a></li>
        <li><a style="color: #ff8868;font-weight: bold;text-decoration:underline;" href="{:U('finishedProduct/agentlist')}">渠道列表</a></li>
        <!--<li><a name="importExcel" style="cursor: pointer;">导入成品数据</a></li>-->

    </ul>
    <table class="table table-hover table-bordered">
        <thead>
        <tr>
            <th>图片</th>
            <th>名称、产品编码</th>
            <th>分类、供应商</th>
            <!--<th>品号、编码</th>-->
            <th>定价、折扣、规格</th>
            <th>渠道（单价）</th>
            <!--<th>适应症</th>-->
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <php>
            $agentList = D('Agent')
            ->where(array('enterprise_code'=>$user['enterprise_code']))
            ->select();
        </php>
        <foreach name="list" item="vo">
            <tr>
                <td>
                    <div class="container-item">
                        <img src="{$vo.image_url}" style="width:50px;cursor: pointer;">
                    </div>
                </td>
                <td style="min-width:100px;"><a style="font-weight: bold;">{$vo.name}</a><br/>{$vo.number}</td>
                <td style="min-width:100px;">{$vo.class_name}<br/>[{$vo.supplier_name}]</td>
                <!--<td style="min-width:100px;">{$vo.number}<br/>{$vo.code}</td>-->
                <td style="min-width:120px;"><a style="color: #e94c60">{$vo.price} 元 / {$vo.unit}</a>，  最低折扣：<a style="color: #00a0e9">{$vo.discount}</a><br/>[{$vo.size}]</td>
                <php>
                    $agentStr = "";
                    $agentIdArr = explode(",", $vo["agent_id"]);
                    $agentPriceArr = explode(",", $vo["agent_price"]);

                    foreach ($agentList as $c) {
                    if(in_array($c['agent_id'], $agentIdArr)){
                    if(!isNullOrEmpty($agentStr)){
                    $agentStr .= "，   ";
                    }
                    $key = array_search($c['agent_id'], $agentIdArr);
                    $agentStr .= $c['agent_name'] . "（" .$agentPriceArr[$key]. "）";
                    }
                    }
                </php>
                <td style="min-width:100px; width: 600px;color: #1cc385">{$agentStr}</td>
                <!--<td>{$vo.function}</td>-->
                <!--<td>{$vo.indication}</td>-->
                <td style="width:30px;">
                    <a class="btn btn-info" href='{:U("finishedProduct/edit",array("id"=>$vo["finished_product_id"]))}'>修改</a>
                    <a class="btn btn-danger" onclick="if(confirm('确认删除成品【{$vo.name}】?')==false)return false;else{$('.btn').attr('disabled',true);}" href='{:U("finishedProduct/remove",array("id"=>$vo["finished_product_id"]))}'>删除</a>
                </td>
            </tr>
        </foreach>
        </tbody>
    </table>
    <div class="pagination">{$page}</div>
</div>
<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>